package com.zhdl.modules.common.service.impl;

import com.zhdl.modules.common.dao.ProcessWarnDao;
import com.zhdl.modules.common.entity.ProcessWarnMessage;
import com.zhdl.modules.common.service.ProcessWarnService;
import com.zhdl.modules.common.web.req.ProcessWarnMessageReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
public class ProcessWarnServiceImpl implements ProcessWarnService {

    @Resource
    private ProcessWarnDao processWarnDao;

    @Override
    public void updateProcessWarnInfo(ProcessWarnMessageReq req){
        Optional<ProcessWarnMessage> byId = processWarnDao.findById(req.getId());
        if (byId.isPresent()) {
            ProcessWarnMessage processWarnMessage = byId.get();
            processWarnMessage.setWarnStatus(req.isWarnStatus());
            processWarnMessage.setWarnInfoList(req.getWarnInfoList());
            processWarnDao.save(processWarnMessage);
        } else {
            log.info("当前对象:" + byId.getClass().getSimpleName() + ",为空!!!");
        }
    }

    @Override
    public void saveProcessWarnInfo(ProcessWarnMessage req){
        processWarnDao.save(req);
    }

    @Override
    public ProcessWarnMessage findById(int id){
        Optional<ProcessWarnMessage> byId = processWarnDao.findById(id);
        return byId.orElse(null);
    }

    @Override
    public List<ProcessWarnMessage> findAllWarnInfo(){
        return processWarnDao.findAll();
    }

    @Override
    public Page<ProcessWarnMessage> findAllByPage(Pageable pageable){
        return processWarnDao.findAll(pageable);
    }

}
